<?php

/**
 * This is the model class for table "transference".
 *
 * The followings are the available columns in table 'transference':
 * @property integer $id
 * @property integer $player
 * @property integer $team_owner_id
 * @property integer $team_buyer_id
 * @property integer $price
 * @property string $observation
 *
 * The followings are the available model relations:
 * @property Player $player0
 * @property Team $teamBuyer
 * @property Team $teamOwner
 */
class Transference extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'transference';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('player, team_owner_id, team_buyer_id, price,', 'required'),
			array('player, team_owner_id, team_buyer_id, price', 'numerical', 'integerOnly'=>true),
			array('price','length','max'=>4),
			array('observation', 'length', 'max'=>250),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, player, status, team_owner_id, team_buyer_id, price, observation', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'player0' => array(self::BELONGS_TO, 'Player', 'player'),
			'teamBuyer' => array(self::BELONGS_TO, 'Team', 'team_buyer_id'),
			'teamOwner' => array(self::BELONGS_TO, 'Team', 'team_owner_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'player' => 'Jogador',
			'team_owner_id' => 'Time Proprietário',
			'team_buyer_id' => 'Time Comprador',
			'price' => 'Preço',
			'observation' => 'Observação',
			'status' => 'Status'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('player',$this->player);
		$criteria->compare('team_owner_id',$this->team_owner_id);
		$criteria->compare('team_buyer_id',$this->team_buyer_id);
		$criteria->compare('price',$this->price);
		$criteria->compare('observation',$this->observation,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Transference the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
